package com.reger.easemob.api.impl;

import java.io.IOException;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class Api {

	protected <T> T call(Call<T> call) {
		try {
			return call.execute().body();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	
	protected <T> void asyncCall(Call<T> call,Call_<T> succees, Call_<Throwable> error) {
		call.enqueue(new Callback<T>() {
			@Override
			public void onResponse(Call<T> call, Response<T> response) {
				succees.call(response.body());
			}

			@Override
			public void onFailure(Call<T> call, Throwable throwable) {
				error.call(throwable);
			}
		});
	}
}
